import { defineConfig, dynamicImport } from 'umi';

import pageRoutes from './router.config';
import alias from './alias';
import theme from './theme';
import qiankun from './qiankun';

//* 设置环境
var define;
var environment = process.env.PROJECT_ENV || 'localhost';
if (environment == 'localhost') define = require('./environments/localhost').default;
if (environment == 'dev') define = require('./environments/dev').default;
if (environment == 'test') define = require('./environments/test').default;
if (environment == 'online') define = require('./environments/online').default;
if (environment == 'demonstrate') define = require('./environments/demonstrate').default;

console.log('--------------------------------------------');
console.log(`--------------当前环境是${environment}----------------`);
console.log('--------------------------------------------');
console.log(define);

export default defineConfig({
  // 设置编译模式
  nodeModulesTransform: {
    type: 'none',
    exclude: [],
  },

  // 静态化 一个路由文件对应一个html文件 (为了百度爬虫以及谷歌爬虫)
  exportStatic: {},

  //按需加载
  dynamicImport: {
    loading: '@/components/basicComp/PageLoading/index',
  },

  // dva
  dva: {},

  // antd
  antd: {},

  //路由配置
  routes: pageRoutes,

  // 国际化配置
  locale: {
    antd: true, // 是否启用antd的<LocaleProvider />  ------由之前的enbale改为 antd
    default: 'zh-CN', //默认语言 zh-CN
    baseNavigator: true, //为true时，用navigator.language的值作为默认语言
    baseSeparator: '-', //语言之间的分隔符
  },

  //多环境配置
  define: define,

  //别名文件的指向
  alias: alias,

  // less变量
  theme: theme,

  //缓存穿透
  hash: true,

  // 配置需要兼容的浏览器最低版本
  targets: {
    ie: 11,
  },

  // 忽略 moment 的 locale 文件，用于减少尺寸。
  ignoreMomentLocale: true,

  title: false,

  // 配置微前端
  qiankun: qiankun,

  // 拆共用包
  externals: {
    jquery: 'jQuery',
    immutable: 'Immutable',
    lodash: '_',
    'rxjs-compat': 'rxjs',
    'bignumber.js': 'BigNumber',
    'whatwg-fetch': 'WHATWGFetch',
    eventProxy: 'EventProxy',
    storejs: 'store',
    react: 'React',
    'react-dom': 'ReactDOM',
  },

  // // 统计分析
  // analytics: {
  //   ga: 'google analytics code',
  //   baidu: '5a66cxxxxxxxxxx9e13',
  // },
});
